#include <stdio.h>

double rnd(double *d)
{
    int m = 65536, u = 2053, v = 13849, t;

    *d = u*(*d) + v;
    t = *d/m;
    *d = *d - m*t;

    return *d/m * 9;
}

int rab(int a, int b, int *r)
{
    int s = b-a+1, p;

    s = s - 1;
    s = s | (s >> 1);
    s = s | (s >> 2);
    s = s | (s >> 4);
    s = s | (s >> 8);
    s = s | (s >> 16);
    s = s + 1 ;
    s <<= 2;

    *r = (5*(*r))%s;
    p = (*r)/4 + a;

    if (p > b)
        return rab(a, b, r);
    else
        return p;
}

int main(int argc, char *argv[])
{
    int i, r = 5;
    double d = 23.0;

    for (i = 0; i < 10; i++) {
        printf("%g\n", rnd(&d));
    }

    for (i = 0; i < 10; i++) {
        printf("%d\n", rab(100, 200, &r));
    }

    return 0;
}
